<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // let promise = new Promise((res, rej) => {
        //         res('cj');
        // rej('sb');
        // })
        // promise.then((res) => {
        //     console.log(res);
        // }, (err) => {
        //     console.log(err);
        // })

        // let p_res = promise.then();
        // console.log(promise);
        // console.log(p_res);
        // console.log(promise == p_res);

        let delay = (ms) => {
            return new Promise((resolve) => {
                setTimeout(resolve, ms);
            })
        }
        let p1 = delay(1000).then(() => {
            console.log('p1');
            return 'p1';
        });
        let p2 = delay(2000).then(() => {
            console.log('p2');
            return 'p2';
        });

        let p = Promise.race([p1, p2]).then(
            (res) => {
                console.log(res);
            },
            (err) => {
                console.log(err);
            }
        )
    </script>
</body>

</html>